/*
打印字符串的全排列
 */
/**
 *
 * @param str {string}
 */
function printAllPermutation (str) {
  const chars = str.match(/./g)
  _process(chars, 0)
}

/**
 *
 * @param chars {Array}
 * @param index {number}
 * @private
 */
function _process (chars, index) {
  if (index === chars.length - 1) {
    console.log(chars.join(''))
    return
  }
  for (let i = index; i < chars.length; i++) {
    swap(chars, index, i)
    _process(chars, index + 1)
    swap(chars, index, i)
  }
}

function swap (arr, i, j) {
  const temp = arr[i]
  arr[i] = arr[j]
  arr[j] = temp
}

printAllPermutation('abc')
